
var picsLoading = {
    listObj:$(".pic-list"),
    showPic:function (obj,index,time) {
        //obj：将执行懒加载图片元素的jQuery对象
        //index：obj在所有需加载的图片中的序号
        //time：默认的加载图片的时间间隔
        time = time || 100;
        setTimeout(function () {
            var src= obj.attr("data-src");
            obj.attr("src",src);
            obj.removeClass("lazy");
            console.log(index)
        },time*index);
    },
    showPics:function (time) {
        var count=0,
            self = this,
            winH = $(window).height(),
            scrollT = $(window).scrollTop(),
            lazyPic = self.listObj.find(".lazy");
        lazyPic.each(function () {
            var $self = $(this),
                top = $self.offset().top;
            top = top -scrollT - winH;
            if(top<0){
                count++;
                self.showPic($self,count,time);
            }
        });
    },
    init:function () {
        var self = this;
        this.showPics(50);
        $(window).on("scroll",function () {
            self.showPics(150);
        });
    }
};
picsLoading.init();